package com.xcdh.trading.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcdh.trading.entity.AStock;
import com.xcdh.trading.entity.IndustryCapitalFlow;
import com.xcdh.trading.entity.SectorCapitalFlow;
import com.xcdh.trading.mapper.IndustryCapitalFlowMapper;
import com.xcdh.trading.response.TradingRes;
import com.xcdh.trading.service.AStockService;
import com.xcdh.trading.service.IndustryCapitalFlowService;
import com.xcdh.trading.util.TuShareApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 行业资金流向服务实现类，继承 ServiceImpl 实现具体的业务逻辑
 */
@Service
public class IndustryCapitalFlowServiceImpl extends ServiceImpl<IndustryCapitalFlowMapper, IndustryCapitalFlow> implements IndustryCapitalFlowService {
    @Autowired
    private AStockService aStockService ;

    @Override
    public void syncIndustryCapitalFlow(String tradeDate) {
        TradingRes tradingRes = TuShareApi.post("moneyflow_ind_ths", tradeDate);
        List<IndustryCapitalFlow> flowList = tradingRes.parse(IndustryCapitalFlow.class);
        for (IndustryCapitalFlow capitalFlow : flowList) {
            IndustryCapitalFlow capitalFlow1 = lambdaQuery()
                    .eq(IndustryCapitalFlow::getTsCode, capitalFlow.getTsCode())
                    .eq(IndustryCapitalFlow::getTradeDate, capitalFlow.getTradeDate()).one();
            if(capitalFlow1 == null){
                save(capitalFlow) ;
            }
        }
    }
    // 可以在这里实现自定义的业务逻辑方法
}
